<template>
  <a-modal
    :zIndex="zIndex"
    :title="title"
    :visible="visible"
    @cancel="handleCancel"
    width="850px"
    :cancelText="$t('关闭')"
    :confirmLoading="confirmLoading"
    v-drag
  >
    <template slot="footer">
      <a-row :gutter="24">
        <a-col :span="12">
          <div style="text-align: left" v-if="!dataForm.id">
            <a-checkbox v-model="isContinue" @change="changeAddState"></a-checkbox> {{ $t('连续添加') }}
          </div>
        </a-col>
        <a-col :span="12">
          <a-button @click="handleCancel" :disabled="confirmLoading">{{ $t('取消') }}</a-button>
          <a-button type="primary" @click="handleOk" v-if="!disable" :disabled="confirmLoading">{{
            $t('保存')
          }}</a-button>
        </a-col>
      </a-row>
    </template>
    <div style="height: 500px; overflow-y: auto">
      <a-row style="margin-left: 10px">
        <a-col :span="24">
          <a-form-model
            ref="dataForm"
            :rules="rules"
            :model="dataForm"
            :label-col="labelCol"
            :wrapper-col="wrapperCol"
            v-enterToNext
          >
            <a-row>
              <div style="margin: 0 0 10px -10px; color: black; font-weight: 500; font-size: 15px">
                {{ $t('基本信息') }}
              </div>
              <a-col :span="12">
                <a-form-model-item prop="code" style="margin-bottom: 10px" :label="$t('商品编码')">
                  <a-input v-model="dataForm.code" ref="code" :disabled="disable"></a-input>
                </a-form-model-item>
                <a-form-model-item prop="name" style="margin-bottom: 10px" :label="$t('商品名称')">
                  <a-input v-model="dataForm.name" :disabled="disable"></a-input>
                </a-form-model-item>
                <a-form-model-item prop="kind" style="margin-bottom: 10px" :label="$t('商品分类')">
                  <a-tree-select
                    show-search
                    :filterTreeNode="filterTreeNode"
                    :disabled="disable"
                    allowClear
                    v-model="dataForm.kind"
                    :dropdownStyle="{ maxHeight: '250px', overflow: 'auto' }"
                    :tree-data="treeData"
                    :placeholder="$t('请选择')"
                    :getPopupContainer="triggerNode => { return triggerNode.parentNode || document.body }"
                  />
                </a-form-model-item>
                <a-form-model-item
                  prop="cost"
                  style="margin-bottom: 10px"
                  :label="$t('参考成本')"
                >
                  <a-input-number v-model="dataForm.cost" :disabled="disable"

                                  :formatter="formatter"
                                  :parser="parser"
                                  style="width: 100%;"
                                  :precision="2"
                  ></a-input-number>
                </a-form-model-item>
              </a-col>
              <a-col :span="12">
                <a-col :span="24" style="padding-right: 0">
                  <a-form-model-item
                    prop="picture"
                    :label="$t('图片')"
                    :labelCol="{ span: 3 }"
                    :wrapperCol="{ span: 18 }"
                  >
                    <div>
                      <j-upload v-model="dataForm.picture" accept="jpg,jpeg,png,gif,webp" fileType="image" :disabled="disable"></j-upload>
                      <div style="color: #f7b926; line-height: 1.2">
                        {{ $t('建议尺寸：750*750，大小不要超过500KB') }}
                      </div>
                    </div>
                  </a-form-model-item>
                </a-col>
              </a-col>
            </a-row>
            <a-row style="margin-left: 20px">
              <div style="margin: 10px 0 10px -30px; color: black; font-weight: 500; font-size: 15px">
                {{ $t('包含卖品') }}
              </div>
              <a-col v-if="!disable">
                <a-table
                  :columns="setMealGoodsTable.columns"
                  :dataSource="setMealGoodsTable.dataSource"
                  bordered
                  class="customTable"
                  :pagination="false"
                  style="padding-left: 11px"
                >
                  <template slot="action" slot-scope="text, record">
                    <a-icon type="close" @click="deleteGoods(text, record)" />
                  </template>
                  <template slot="select" slot-scope="text, record, index">
                    <a-select
                      v-model="record.goodsForm"
                      :placeholder="$t('请选择商品形态')"
                      @change="(value) => handleGoodsChange(value, index)"
                    >
                      <a-select-option v-for="good in goodsFormList" :key="good.value">{{
                        good.title
                      }}</a-select-option>
                    </a-select>
                  </template>
                  <template slot="selectTwo" slot-scope="text, record, index">
                    <a-select
                      v-model="record.goodsId"
                      show-search
                      :placeholder="$t('请下拉或者输入商品名称选择商品')"
                      :filter-option="false"
                      :not-found-content="null"
                      @search="(val) => handleGoodsSearch(val, record)"
                      :disabled="!record.goodsForm"
                    >
                      <div slot="dropdownRender" slot-scope="menu">
                        <div
                          style="padding: 4px 8px; cursor: pointer"
                          @mousedown="(e) => e.preventDefault()"
                          @click="addNewGoods(record, index)"
                        >
                          <a-icon type="plus" /> {{ $t('添加新商品') }}
                        </div>
                        <a-divider style="margin: 4px 0 0" />
                        <v-nodes :vnodes="menu" />
                      </div>
                      <a-select-option v-for="good in addGoodsListTwo" :key="good.id" :value="good.id">{{ good.name }}</a-select-option>
                    </a-select>
                  </template>
                  <template slot="inputNum" slot-scope="text, record">
                    <a-input-number v-model="record.amount"

                                    :formatter="formatter"
                                  :parser="parser"
                                    style="width: 100%;"></a-input-number>
                  </template>
                  <template slot="isGift" slot-scope="text, record">
                    <a-checkbox v-model="record.isGiftState" @change="clickIsGift"></a-checkbox>
                  </template>
                </a-table>
              </a-col>
              <a-col v-if="disable">
                <a-table
                  :columns="setMealGoodsTable.columns1"
                  :dataSource="setMealGoodsTable.dataSource"
                  bordered
                  class="customTable"
                  :pagination="false"
                  style="padding-left: 11px"
                >
                  <template slot="isGift" slot-scope="text, record">
                    <span v-if="record.isGift == 0">{{ $t('否') }}</span>
                    <span v-if="record.isGift == 1">{{ $t('是') }}</span>
                  </template>
                </a-table>
              </a-col>
            </a-row>
            <a-row style="margin-left: 20px">
              <div style="margin: 10px 0 10px -30px; color: black; font-weight: 500; font-size: 15px">
                {{ $t('销售兑换设置') }}
              </div>
              <a-col :span="24">
                <a-row>
                  <a-col :span="6">
                    <a-form-model-item prop="allowMemberDiscounts" style="margin-bottom: 5px" :labelCol="{ span: 0 }" :wrapperCol="{ span: 22 }">
                      <a-checkbox v-model="dataForm.allowMemberDiscounts" :disabled="disable">{{
                        $t('享受会员优惠')
                      }}</a-checkbox>
                    </a-form-model-item>
                  </a-col>
                  <a-col :span="6" v-if="taxSetting == 1">
                    <a-form-model-item prop="allowTax" style="margin-bottom: 5px;margin-left: 10px" :labelCol="{ span: 0 }" :wrapperCol="{ span: 22 }">
                      <a-checkbox :checked="dataForm.allowTax == 1" :disabled="disable" @change="changeSelectState">{{
                        $t('销售加税')
                      }}</a-checkbox>
                    </a-form-model-item>
                  </a-col>
                </a-row>
              </a-col>
              <a-col :span="24">
                <a-row>
                  <a-col :span="6">
                    <a-form-model-item prop="allowSale" style="margin-bottom: 5px">
                      <a-checkbox v-model="dataForm.allowSales" :disabled="disable">{{ $t('允许销售') }}</a-checkbox>
                    </a-form-model-item>
                  </a-col>
                  <a-col :span="6">
                    <a-form-model-item prop="price" style="margin-bottom: 5px" :label="$t('售价')">
                      <a-input-number v-model="dataForm.price" :disabled="disable" @change="changePrice"

                                      :formatter="formatter"
                                  :parser="parser"
                                      style="width: 100%;"
                                      :precision="2"
                      ></a-input-number>
                    </a-form-model-item>
                  </a-col>
                  <a-col :span="6" v-if="taxSetting == 2">
                    <a-form-model-item prop="taxPrice" style="margin-bottom: 5px" :label="$t('其中税费')" :labelCol="{ span: 8 }" :wrapperCol="{ span: 16 }">
                      {{dataForm.taxPrice}}
                    </a-form-model-item>
                  </a-col>
                  <a-col :span="6" v-if="taxSetting == 2">
                    <a-form-model-item prop="taxPrice" style="margin-bottom: 5px; opacity: 0" :label="$t('其中税费')" :labelCol="{ span: 8 }" :wrapperCol="{ span: 16 }">
                      <a-input-number v-model="dataForm.taxPrice" :disabled="disable"

                                      :formatter="formatter"
                                  :parser="parser"
                                      style="width: 100%;"
                                      :precision="2"
                      ></a-input-number>
                    </a-form-model-item>
                  </a-col>
                  <a-col :span="6">
                    <a-form-model-item prop="allowCoins" style="margin-bottom: 5px">
                      <a-checkbox v-model="dataForm.allowCoins" :disabled="disable">{{ $t('允许币兑换') }}</a-checkbox>
                    </a-form-model-item>
                  </a-col>
                  <a-col :span="6">
                    <a-form-model-item prop="coin" style="margin-bottom: 5px" :label="$t('代币')">
                      <a-input-number v-model="dataForm.coin" :disabled="disable"

                                      :formatter="formatter"
                                  :parser="parser"
                                      style="width: 100%;"
                      ></a-input-number>
                    </a-form-model-item>
                  </a-col>
                  <a-col :span="6">
                    <a-form-model-item prop="allowLotterys" style="margin-bottom: 5px" label="" label-width="50px">
                      <a-checkbox v-model="dataForm.allowLotterys" ref="allowLotterys" :disabled="disable">{{
                        $t('允许彩票兑换')
                      }}</a-checkbox>
                    </a-form-model-item>
                  </a-col>
                  <a-col :span="6">
                    <a-form-model-item prop="lottery" :label="$t('彩票')" style="margin-bottom: 5px">
                      <a-input-number v-model="dataForm.lottery" ref="lottery" :disabled="disable"

                                      :formatter="formatter"
                                  :parser="parser"
                                      style="width: 100%;"
                      ></a-input-number>
                    </a-form-model-item>
                  </a-col>
                  <a-col :span="6">
                    <a-form-model-item prop="allowPointss" style="margin-bottom: 5px">
                      <a-checkbox
                        v-model="dataForm.allowPointss"
                        ref="allowPointss"
                        :disabled="disable"
                        style="width: 110%"
                        >{{ $t('允许A币兑换') }}</a-checkbox
                      >
                    </a-form-model-item>
                  </a-col>
                  <a-col :span="6">
                    <a-form-model-item prop="points" style="margin-bottom: 5px" :label="$t('A币')">
                      <a-input-number v-model="dataForm.points" :disabled="disable"

                                      :formatter="formatter"
                                  :parser="parser"
                                      style="width: 100%;"
                      ></a-input-number>
                    </a-form-model-item>
                  </a-col>
                  <a-col :span="6">
                    <a-form-model-item prop="allowIntegrals" style="margin-bottom: 5px">
                      <a-checkbox v-model="dataForm.allowIntegrals" :disabled="disable">{{
                        $t('允许积分兑换')
                      }}</a-checkbox>
                    </a-form-model-item>
                  </a-col>
                  <a-col :span="6">
                    <a-form-model-item prop="integral" style="margin-bottom: 5px" :label="$t('积分')">
                      <a-input-number v-model="dataForm.integral" ref="integral" :disabled="disable"

                                      :formatter="formatter"
                                  :parser="parser"
                                      style="width: 100%;"
                      ></a-input-number>
                    </a-form-model-item>
                  </a-col>
                  <a-col :span="6">
                    <a-form-model-item
                      prop="allowAlotterys"
                      :labelCol="{ span: 8 }"
                      :wrapperCol="{ span: 16 }"
                      style="margin-bottom: 5px"
                    >
                      <a-checkbox v-model="dataForm.allowAlotterys" ref="allowAlotterys" :disabled="disable">{{
                        $t('允许A票兑换')
                      }}</a-checkbox>
                    </a-form-model-item>
                  </a-col>
                  <a-col :span="6">
                    <a-form-model-item prop="alottery" style="margin-bottom: 5px" :label="$t('A票')">
                      <a-input-number v-model="dataForm.alottery" ref="alottery" :disabled="disable"

                                      :formatter="formatter"
                                  :parser="parser"
                                      style="width: 100%;"
                      ></a-input-number>
                    </a-form-model-item>
                  </a-col>
                </a-row>
              </a-col>
            </a-row>
            <a-row style="margin-left: 20px">
              <div style="margin: 10px 0 10px -30px; color: black; font-weight: 500; font-size: 15px">
                {{ $t('回收设置') }}
              </div>
              <a-col :span="24">
                <div>
                  <div style="margin-bottom: 10px" v-for="(item, index) in recycleList" :key="index">
                    <a-checkbox
                      style="padding-top: 6px; color: black; font-weight: 500; font-size: 15px"
                      :checked="item.status == 'Y'"
                      @change="(e) => changeStatus(e, index)"
                      :disabled="disable"
                      >{{ $t('允许回收') }}</a-checkbox
                    >
                    <span style="padding-left: 20px">{{ $t('回收类型') }}：</span>
                    <a-select
                      :placeholder="$t('请选择')"
                      v-model="item.recyclingType"
                      style="width: 200px"
                      :disabled="disable || item.status == 'N'"
                    >
                      <a-select-option v-for="type in paytypeList" :key="type.name" :value="type.name">
                        <span>{{ type.name_dictText }}</span>
                      </a-select-option>
                    </a-select>
                    <span style="padding-left: 20px">{{ $t('回收值') }}：</span>
                    <a-input-number
                      v-model="item.recyclingValue"
                      style="width: 140px"
                      :disabled="disable || item.status == 'N'"
                      :formatter="formatter"
                      :parser="parser"
                      :min="1"
                      :precision="0"
                    ></a-input-number>
                  </div>
                </div>
              </a-col>
            </a-row>
            <a-row style="margin-left: 20px">
              <div style="margin: 10px 0 10px -30px; color: black; font-weight: 500; font-size: 15px">
                {{ $t('更多设置') }}
              </div>
              <a-row>
                <a-col :span="9">
                  <a-form-model-item prop="state" style="margin-bottom: 5px" :label="$t('上架状态')">
                    <a-radio-group v-model="dataForm.state" ref="state" :disabled="disable">
                      <a-radio value="Y">{{ $t('上架') }}</a-radio>
                      <a-radio value="N">{{ $t('下架') }}</a-radio>
                    </a-radio-group>
                  </a-form-model-item>
                </a-col>
                <a-col :span="9">
                  <a-form-model-item style="margin-bottom: 5px">
                    <a-checkbox v-model="dataForm.authSales" :disabled="disable">{{ $t('授权销售') }}</a-checkbox>
                  </a-form-model-item>
                </a-col>
              </a-row>
              <a-row>
                <a-col :span="9">
                  <a-form-model-item prop="limitCycle" style="margin-bottom: 5px" :label="$t('限购类型')">
                    <j-dict-select-tag
                      :placeholder="$t('请选择')"
                      style="width: 100px"
                      v-model="dataForm.limitCycle"
                      @change="changelimitCycleState"
                      :disabled="disable"
                      dictCode="bis_goods_infor.limit_cycle"
                    />
                  </a-form-model-item>
                </a-col>
                <a-col :span="7" style="margin-left: -110px">
                  <a-form-model-item
                    prop="limitNum"
                    :labelCol="{ span: 7 }"
                    :wrapperCol="{ span: 16 }"
                    style="margin-bottom: 0px"
                    :label="$t('限购数量')"
                  >
                    <a-input v-model="dataForm.limitNum" :disabled="limitCycledisable"></a-input>
                  </a-form-model-item>
                </a-col>
                <a-col :span="10">
                  <div style="color: #f6aa64; margin-top: 5px">
                    {{ $t('(每个会员在特定的限购周期内最大允许的购买数量)') }}
                  </div>
                </a-col>
              </a-row>
              <a-row>
                <a-col>
                  <a-form-model-item
                    prop="allowMemberType"
                    :labelCol="{ span: 2 }"
                    :wrapperCol="{ span: 20 }"
                    style="margin-bottom: 5px; margin-left: 4px"
                    :label="$t('适用会员')"
                  >
                    <a-radio-group
                      v-model="allowMemberType"
                      @change="getTypeValue"
                      :disabled="disable"
                      style="margin-left: 5px"
                    >
                      <a-radio value="">{{ $t('全部') }}</a-radio>
                      <a-radio value="part">{{ $t('指定会员') }}</a-radio> </a-radio-group
                    ><br />
                    <a-checkbox-group
                      :span="24"
                      v-if="memberShow"
                      v-model="dataForm.allowMemberTypes"
                      style="margin-top: 6px; margin-left: 5px"
                    >
                      <a-checkbox style="margin-left: 8px" :value="item.id" v-for="item in memberList" :key="item.id">{{
                        item.name
                      }}</a-checkbox>
                    </a-checkbox-group>
                  </a-form-model-item>
                </a-col>
              </a-row>
              <a-row>
                <a-col>
                  <a-form-model-item
                    prop="allowDeviceType"
                    :labelCol="{ span: 2 }"
                    :wrapperCol="{ span: 20 }"
                    style="margin-bottom: 5px; margin-left: 4px"
                    :label="$t('适用渠道')"
                  >
                    <a-radio-group
                      v-model="allowDeviceType"
                      @change="getDeviceTypeValue"
                      :disabled="disable"
                      style="margin-left: 5px"
                    >
                      <a-radio value="">{{ $t('全部') }}</a-radio>
                      <a-radio value="part">{{ $t('指定渠道') }}</a-radio>
                    </a-radio-group>
                    <br />
                    <a-checkbox-group
                      v-if="deviceTypeShow"
                      v-model="dataForm.allowDeviceTypes"
                      style="margin-top: 6px; margin-left: 5px"
                      :disabled="disable"
                      @change="getDeviceList"
                    >
                      <a-checkbox
                        style="margin-left: 8px"
                        :value="item.type"
                        v-for="item in deviceTypeList"
                        :key="item.type"
                        >{{ item.type_dictText }}
                      </a-checkbox>
                    </a-checkbox-group>
                  </a-form-model-item>
                </a-col>
              </a-row>
              <a-row>
                <a-col>
                  <a-form-model-item
                    prop="allowDevice"
                    :labelCol="{ span: 2 }"
                    :wrapperCol="{ span: 20 }"
                    style="margin-bottom: 5px; margin-left: 4px"
                    :label="$t('销售终端')"
                  >
                    <a-radio-group
                      v-model="allowDevice"
                      @change="getDeviceValue"
                      :disabled="disable"
                      style="margin-left: 5px"
                    >
                      <a-radio value="">{{ $t('全部') }}</a-radio>
                      <a-radio value="part">{{ $t('指定终端') }}</a-radio>
                    </a-radio-group>
                    <br />
                    <a-checkbox-group
                      v-if="deviceShow"
                      v-model="dataForm.allowDevices"
                      style="margin-top: 6px; margin-left: 5px"
                      :disabled="disable"
                    >
                      <a-checkbox style="margin-left: 8px" :value="item.id" v-for="item in deviceList" :key="item.id"
                        >{{ item.name }}
                      </a-checkbox>
                    </a-checkbox-group>
                  </a-form-model-item>
                </a-col>
              </a-row>
              <a-row>
                <a-col :span="24">
                  <a-form-model-item
                    prop="comment"
                    :labelCol="{ span: 2 }"
                    :wrapperCol="{ span: 20 }"
                    :label="$t('商品简介')"
                    style="margin-left: 4px"
                  >
                    <a-textarea v-model="dataForm.comment" ref="comment" :rows="2" :disabled="disable" />
                  </a-form-model-item>
                </a-col>
              </a-row>
              <a-row>
                <a-col :span="24">
                  <a-form-model-item
                    prop="details"
                    :label="$t('商品详情')"
                    :labelCol="{ span: 2 }"
                    :wrapperCol="{ span: 20 }"
                    style="margin-left: 4px"
                  >
                    <div style="color: #e28909">
                      {{
                        $t('用于小程序商品详情的展示；建议图片宽度375px，上传多张图片时，每张图片的宽度应该保持一致。')
                      }}
                    </div>
                    <j-upload
                      v-model="dataForm.details"
                      accept="jpg,jpeg,png,gif,webp"
                      fileType="image"
                      :disabled="disable"
                      class="detail-upload"
                      text="upload"
                    ></j-upload>
                  </a-form-model-item>
                </a-col>
              </a-row>
            </a-row>
            <!-- <a-row style="margin-left: 20px">
              <div style="margin: 10px 0 10px -30px; color: black; font-weight: 500; font-size: 15px">
                {{ $t('第三方核销') }}
              </div>
              <a-form-model-item>
                <div style="display: inline-block" v-for="(item, index, key) in dataForm.bisGoodsThirdList" :key="key">
                  {{ item.channel_dictText }}: {{ item.thirdCode }}
                  <a-icon
                    @click="delGoodsThird(item, index, 'exclude')"
                    style="color: #1890ff; cursor: pointer"
                    type="close"
                    :disabled="disable"
                    v-if="!disable"
                  />，
                </div>
                <span>
                  <a href="javascript:void(0);" @click="addGoodsThird()" style="margin-left: 10px" v-if="!disable">{{
                    $t('添加')
                  }}</a>
                </span>
              </a-form-model-item>
            </a-row> -->
            <a-row style="margin-left: 20px">
              <div style="margin: 0 0 10px -30px">
                <a-checkbox
                  style="padding-top: 6px; color: black; font-weight: 500; font-size: 15px"
                  :checked="chargeAfter"
                  @change="changeChargeStatue"
                  >{{ $t('充值后晋级') }}</a-checkbox
                >
              </div>
              <a-col :span="24">
                <div>
                  <div style="margin-bottom: 10px" v-for="(item, index) in elevation" :key="index">
                    <a-select
                      :placeholder="$t('请选择晋级前会员类型')"
                      v-model="item.memberType"
                      style="width: 200px; margin-left: 8px"
                      :disabled="item.disable"
                    >
                      <a-select-option v-for="level in levelList" :key="level.id" :value="level.id">
                        <span>{{ level.level }}{{ level.name }}</span>
                      </a-select-option>
                    </a-select>
                    <span style="margin-left: 8px">{{ $t('晋级到') }}</span>
                    <a-select
                      :placeholder="$t('请选择晋级后会员类型')"
                      v-model="item.memberTypeAfter"
                      style="width: 200px; margin-left: 8px"
                      :disabled="item.disable"
                    >
                      <a-select-option v-for="level in levelList" :key="level.id" :value="level.id">
                        <span>{{ level.level }}{{ level.name }}</span>
                      </a-select-option>
                    </a-select>
                    <a href="javascript:void(0);" style="margin-left: 8px" v-if="item.disable"
                      ><a-icon type="edit" @click="editElevation(index)"
                    /></a>
                    <a href="javascript:void(0);" style="margin-left: 8px" v-else
                      ><a-icon type="check" @click="saveElevation(item, index)"
                    /></a>
                    <a href="javascript:void(0);" style="margin-left: 8px"
                      ><a-icon type="close" @click="deleteElevation(index)"
                    /></a>
                  </div>
                  <a href="javascript:void(0);" @click="addElevation" style="line-height: 32px; margin-left: 10px">{{
                    $t('添加')
                  }}</a>
                </div>
              </a-col>
              <div style="margin: 0 0 10px -30px">
                <a-checkbox style="padding-top: 6px" :checked="renewalAfter" @change="changeRenewalStatue">{{
                  $t('充值后续期')
                }}</a-checkbox>
                <span v-for="(item, index) in renewalList" :key="index">
                  <j-dict-select-tag
                    :placeholder="$t('请选择')"
                    style="width: 100px"
                    v-model="item.type"
                    :disabled="disable"
                    dictCode="bis_member_rule_renewal.type"
                  />
                  <span style="margin-left: 8px">{{ $t('开始续期') }}</span>
                  <a-input v-model="item.renewal" style="width: 140px; margin-left: 8px"></a-input>
                  <span style="margin-left: 8px">{{ $t('月') }}</span>
                </span>
              </div>              
              <div style="margin: 0 0 10px -30px">
                <a-checkbox
                  style="padding-top: 6px;"
                  v-model="dataForm.freeWithRecharge"
                  >{{ $t('开卡直接购买免收押金') }}</a-checkbox
                >
              </div>
            </a-row>
          </a-form-model>
        </a-col>
      </a-row>
    </div>
    <goods-info-modal ref="modalForm" @ok="modalFormOk" />
    <coupons-modal ref="conponsForm" @ok="modalFormOk"></coupons-modal>
    <goods-info-a-coin-modal ref="aCoInModalForm" @ok="modalFormOk" />
    <time-limit-coin-modal ref="timeLimitCoin" @ok="modalFormOk" />
    <!-- <bis-goods-third-modal ref="goodsThirdmodel" @ok="addGoodsThirdCallback"></bis-goods-third-modal> -->
  </a-modal>
</template>

<script>
import Vue from 'vue'
import { TENANT_ID } from '@/store/mutation-types'
import { httpAction, getAction, isEmpty } from '@/api/manage'
import { initDictOptions } from '@/components/dict/JDictSelectUtil'
/* import BisGoodsThirdModal from './BisGoodsThirdModal' */
import CouponsModal from './CouponsModal'
import GoodsInfoModal from './GoodsInfoModal'
import GoodsInfoACoinModal from './GoodsInfoACoinModal'
import TimeLimitCoinModal from './TimeLimitCoinModal'
import {formatter, parser} from "@api/comm";
let that,nInd
export default {
  name: 'GoodsInfoMealModal',
  components: {
    /* BisGoodsThirdModal, */
    GoodsInfoModal,
    CouponsModal,
    GoodsInfoACoinModal,
    TimeLimitCoinModal,
    VNodes: {
      functional: true,
      render: (h, ctx) => ctx.props.vnodes,
    },
  },
  data() {
    return {
      formatter,
      parser,
      zIndex: 1001,
      title: '',
      confirmLoading: false,
      dataForm: {
        code: '',
        name: '',
        allowOuts: false,
        allowWarns: '',
        warnNum: 0,
        verifyType: '1',
        allowMemberDiscounts: false,
        allowTax: 1,
        allowCoins: '',
        allowLotterys: '',
        allowPointss: '',
        allowSales: '',
        allowIntegrals: '',
        allowAlotterys: '',
        authSale: '',
        authSales: false,
        state: '',
        allowMemberType: '',
        allowDeviceType: '',
        allowDevice: '',
        form: '', //形态
        bisGoodsPackageList: [],
        validityType: '0',
        /* bisGoodsThirdList: [], */
      },
      treeData: [],
      deviceTypeShow: false,
      deviceShow: false,
      memberShow: false,
      taxSetting: 0,
      visible: false,
      labelCol: {
        xs: { span: 20 },
        sm: { span: 6 },
      },
      wrapperCol: {
        xs: { span: 20 },
        sm: { span: 15 },
      },
      rules: {
        name: [{ required: true, message: this.$t('请输入卖品名称') }],
        kind: [{ required: true, message: this.$t('请选择卖品分类') }],
        cost: [
          { required: true, message: this.$t('请输入卖品参考成本') },
          { pattern: /^\d+.?\d{0,2}$/, message: this.$t('小数点后最多输入两位') },
        ],
        price: [{ pattern: /^\d+.?\d{0,2}$/, message: this.$t('小数点后最多输入两位') }],
        integral: [{ pattern: /^[+]{0,1}(\d+)$/, message: this.$t('请输入0或正整数') }],
        lottery: [{ pattern: /^[+]{0,1}(\d+)$/, message: this.$t('请输入0或正整数') }],
        alottery: [{ pattern: /^[+]{0,1}(\d+)$/, message: this.$t('请输入0或正整数') }],
        points: [{ pattern: /^\d+.?\d{0,2}$/, message: this.$t('小数点后最多输入两位') }]
      },
      url: {
        add: '/goods/bisGoodsInfor/add',
        edit: '/goods/bisGoodsInfor/edit',
        importExcelUrl: '/sys/common/upload',
      },
      memberList: [],
      deviceTypeList: [],
      deviceList: [],
      disable: false,
      limitCycledisable: false,
      allowWarnsdisable: true,
      allowMemberType: '',
      allowDevice: '',
      allowDeviceType: '',
      goodsFormList: [],
      addGoodsListTwo: [],

      //卖品
      setMealGoodsTable: {
        loading: false,
        dataSource: [],
        columns: [
          {
            title: '+',
            dataIndex: 'action',
            align: 'center',
            width: 30,
            customHeaderCell: function (column) {
              return {
                style: {
                  textAlign: 'center',
                  color: '#1890ff',
                  fontSize: '25px',
                  height: '32px',
                  lineHeight: '32px',
                  fontWeight: 'bold',
                  cursor: 'pointer',
                },
                on: {
                  click: () => {
                    that.addGoods()
                  },
                },
              }
            },
            customCell: function (column) {
              return {
                style: {
                  textAlign: 'center',
                  color: '#1890ff',
                  fontSize: '16px',
                  height: '32px',
                  lineHeight: '32px',
                  fontWeight: 'bold',
                  cursor: 'pointer',
                },
              }
            },
            scopedSlots: { customRender: 'action' },
          },
          {
            title: this.$t('商品形态'),
            dataIndex: 'form',
            align: 'center',
            width: 150,
            scopedSlots: { customRender: 'select' },
          },
          {
            title: this.$t('商品名称'),
            dataIndex: 'name',
            align: 'center',
            width: 260,
            scopedSlots: { customRender: 'selectTwo' },
          },
          {
            title: this.$t('数量'),
            key: 'num',
            dataIndex: 'num',
            customHeaderCell: function (column) {
              return {
                style: {
                  textAlign: 'center',
                },
              }
            },
            customCell: function (record, rowIndex) {
              return {
                style: {
                  textAlign: 'right',
                },
              }
            },
            scopedSlots: { customRender: 'inputNum' },
          },
          {
            title: this.$t('是否赠送'),
            key: 'isGift',
            dataIndex: 'isGift',
            customHeaderCell: function (column) {
              return {
                style: {
                  textAlign: 'center',
                },
              }
            },
            scopedSlots: { customRender: 'isGift' },
          },
        ],
        columns1: [
          {
            title: this.$t('商品形态'),
            dataIndex: 'goodsForm_dictText',
            align: 'center',
            width: 150,
          },
          {
            title: this.$t('商品名称'),
            dataIndex: 'name',
            align: 'center',
            width: 260,
          },
          {
            title: this.$t('数量'),
            key: 'amount',
            dataIndex: 'amount',
            align: 'center',
          },
          {
            title: this.$t('是否赠送'),
            key: 'isGift',
            dataIndex: 'isGift',
            align: 'center',
            scopedSlots: { customRender: 'isGift' },
          },
        ],
      },
      goodsPriceRule: {
        isGoodsPriceRule: 0,
        coinRule: 1,
        lotteryRule: 1,
        integralRule: 1,
        pointsRule: 1,
        alotteryRule: 1,
      },
      levelList: [],
      elevation: [],
      chargeAfter: false,
      renewalList: [],
      renewalAfter: false,
      isContinue: true,
      paytypeList: [],
      recycleList: [],
    }
  },
  created() {
    that = this
    nInd = null
  },
  methods: {
    /* addGoodsThird() {
      that.$refs.goodsThirdmodel.edit()
    },
    delGoodsThird(item) {
      that.dataForm.bisGoodsThirdList.forEach((col) => {
        if (col.channel == item.channel && col.thirdCode == item.thirdCode) {
          let index = that.dataForm.bisGoodsThirdList.indexOf(col)
          that.dataForm.bisGoodsThirdList.splice(index, 1)
        }
      })
    },
    addGoodsThirdCallback(item) {
      getAction('/sys/dict/getDictText/bis_goods_third.channel/' + item.channel).then((res) => {
        if (res.success) {
          item.channel_dictText = res.result
          var b = true
          if (that.dataForm.bisGoodsThirdList && that.dataForm.bisGoodsThirdList.length > 0) {
            that.dataForm.bisGoodsThirdList.forEach((col) => {
              if (col.channel == item.channel && col.thirdCode == item.thirdCode) {
                b = false
                return
              }
            })
          } else {
            that.$set(that.dataForm, 'bisGoodsThirdList', [])
          }
          if (b) {
            that.dataForm.bisGoodsThirdList.push(item)
          } else {
            that.$message.warning('该第三方渠道商品已存在')
            return
          }
        }
      })
    }, */
    changeStatus(e, i) {
      that.$set(that.recycleList[i], 'status', e.target.checked ? 'Y' : 'N')
    },
    changePrice() {
      if (that.goodsPriceRule.isGoodsPriceRule == 1) {
        that.$set(that.dataForm, 'coin', that.dataForm.price * that.goodsPriceRule.coinRule)
        that.$set(that.dataForm, 'lottery', that.dataForm.price * that.goodsPriceRule.lotteryRule)
        that.$set(that.dataForm, 'integral', that.dataForm.price * that.goodsPriceRule.integralRule)
        that.$set(that.dataForm, 'points', that.dataForm.price * that.goodsPriceRule.pointsRule)
        that.$set(that.dataForm, 'alottery', that.dataForm.price * that.goodsPriceRule.alotteryRule)
      }
      if(that.taxSetting == 2){
        that.$set(that.dataForm,'taxPrice',(that.dataForm.price - (that.dataForm.price / ( 1 + localStorage.getItem('taxRate') / 100))).toFixed(2))
      }
    },
    getInfo() {
      getAction('/bis/bisSysParameter/list', { name: 'isGoodsPriceRule' }).then((res) => {
        if (res.success) {
          if (res.result.total > 0) {
            that.goodsPriceRule.isGoodsPriceRule = res.result.records[0].ivalue
            if (that.goodsPriceRule.isGoodsPriceRule == 1) {
              getAction('/bis/bisSysParameter/list', {
                name: 'coinRule,lotteryRule,integralRule,pointsRule,alotteryRule',
              }).then((res) => {
                if (res.success) {
                  if (res.result.total > 0) {
                    res.result.records.forEach((el) => {
                      if (el.name == 'coinRule') {
                        that.goodsPriceRule.coinRule = el.dvalue
                      }
                      if (el.name == 'lotteryRule') {
                        that.goodsPriceRule.lotteryRule = el.dvalue
                      }
                      if (el.name == 'integralRule') {
                        that.goodsPriceRule.integralRule = el.dvalue
                      }
                      if (el.name == 'pointsRule') {
                        that.goodsPriceRule.pointsRule = el.dvalue
                      }
                      if (el.name == 'alotteryRule') {
                        that.goodsPriceRule.alotteryRule = el.dvalue
                      }
                    })
                  }
                } else {
                  that.$message.error(res.message)
                }
              })
            }
          }
        } else {
          that.$message.error(res.message)
        }
      })
    },
    addGoods() {
      let obj = {
        goodsForm: '',
        goodsId: '',
        amount: 1,
        isGift: 'N',
      }
      that.setMealGoodsTable.dataSource.push(obj)
    },
    add(value) {
      that.visible = true
      that.isContinue = localStorage.getItem('goodsAddInfo')
        ? JSON.parse(localStorage.getItem('goodsAddInfo')).state
        : true
      that.dataForm = {
        code: '',
        name: '',
        allowOut: 'N',
        allowWarns: '',
        warnNum: 0,
        verifyType: '1',
        cost: '',
        allowMemberDiscount: 'N',
        allowTax: 1,
        allowCoins: '',
        allowLotterys: '',
        allowPointss: '',
        allowSale: 'N',
        allowIntegrals: '',
        allowAlotterys: '',
        authSale: '',
        authSales: false,
        state: 'Y',
        limitCycle: '0',
        allowMemberType: '',
        allowDevices: [],
        allowDevice: '',
        allowDeviceTypes: [],
        allowDeviceType: '',
        form: value,
        species: '2',
        bisGoodsPackageList: [],
        recyclingList: [{ status: 'N' }],
        freeWithRecharge: false,
      }
      that.chargeAfter = false
      that.elevation = [
        {
          memberType: undefined,
          memberTypeAfter: undefined,
          disable: false,
        },
      ]
      that.renewalAfter = false
      that.renewalList = [
        {
          type: '0',
          renewal: '',
        },
      ]
      that.edit(that.dataForm)
    },
    edit(record, state) {
      that.getInfo()
      that.setMealGoodsTable.dataSource = []
      that.disable = state
      that.getMemberList()
      that.getDeviceTypeList()
      that.getDeviceList()
      that.taxSetting = localStorage.getItem('taxSetting')
      that.select()
      that.visible = true
      if (that.disable == true || record.limitCycle == '0') {
        that.limitCycledisable = true
      } else {
        that.limitCycledisable = false
      }
      if (record.allowWarn == 'Y' || that.disable == true) {
        that.allowWarnsdisable = true
      }
      /* if (record.id != undefined) {
        getAction('/goods/bisGoodsThird/list', { goodsId: record.id, pageSize: 999 }).then((res) => {
          if (res.success && res.result.total > 0) {
            that.$set(that.dataForm, 'bisGoodsThirdList', res.result.records)
          }
        })
      } */
      that.chargeAfter = record.allowPromote ? true : false
      that.renewalAfter = record.allowRenewal ? true : false
      that.getLevels()
      that.getGoodsFormList()
      that.getPaytypeList();
      if (record.recyclingList == null || record.recyclingList.length == 0) {
        record.recyclingList = [{ status: 'N' }]
      }
      let recycleList = JSON.parse(JSON.stringify([...record.recyclingList]))
      that.recycleList = recycleList
      if (record.id) {
        getAction('/goods/bisGoodsInfor/queryBisGoodsPackageByMainId', { id: record.id }).then((res) => {
          that.setMealGoodsTable.dataSource = res.result
          let arr = []
          that.setMealGoodsTable.dataSource.forEach((col) => {
            let dtl = {
              id: col.goodsId,
              name: col.goodsInfo[0].name,
            }
            arr.push(dtl)
            if (col.isGift == 1) {
              that.$set(col, 'isGiftState', true)
            } else {
              that.$set(col, 'isGiftState', false)
            }
            that.$set(col, 'name', col.goodsInfo[0].name)
          })
          that.addGoodsListTwo = arr
        })
      }
      if (record.allowMemberDiscount == 'Y') {
        record.allowMemberDiscounts = true
      } else {
        record.allowMemberDiscounts = false
      }
      if (record.allowOut == 'Y') {
        record.allowOuts = true
      } else {
        record.allowOuts = false
      }
      if (record.allowWarn == 'Y') {
        record.allowWarns = true
      } else {
        record.allowWarns = false
      }
      if (record.allowCoin == 'Y') {
        record.allowCoins = true
      } else {
        record.allowCoins = false
      }
      if (record.allowLottery == 'Y') {
        record.allowLotterys = true
      } else {
        record.allowLotterys = false
      }
      if (record.allowPoints == 'Y') {
        record.allowPointss = true
      } else {
        record.allowPointss = false
      }
      if (record.allowSale == 'Y') {
        record.allowSales = true
      } else {
        record.allowSales = false
      }
      if (record.allowIntegral == 'Y') {
        record.allowIntegrals = true
      } else {
        record.allowIntegrals = false
      }
      if (record.allowAlottery == 'Y') {
        record.allowAlotterys = true
      } else {
        record.allowAlotterys = false
      }
      if (record.authSale == '1') {
        record.authSales = true
      } else {
        record.authSales = false
      }

      that.allowMemberType = record.allowMemberType
      if (that.allowMemberType == '' || that.allowMemberType == null || that.allowMemberType == undefined) {
        that.memberShow = false
      } else {
        record.allowMemberTypes = record.allowMemberType.split(',')
        that.allowMemberType = 'part'
        that.memberShow = true
      }

      that.allowDeviceType = record.allowDeviceType
      if (that.allowDeviceType == null || that.allowDeviceType == undefined) {
        that.allowDeviceType = ''
      }
      if (that.allowDeviceType == '') {
        that.deviceTypeShow = false
      } else {
        record.allowDeviceTypes = record.allowDeviceType.split(',')
        that.allowDeviceType = 'part'
        that.deviceTypeShow = true
      }

      that.allowDevice = record.allowDevice
      if (that.allowDevice == '' || that.allowDevice == that || that.allowDevice == undefined) {
        that.deviceShow = false
      } else {
        record.allowDevices = record.allowDevice.split(',')
        that.allowDevice = 'part'
        that.deviceShow = true
      }
      that.dataForm = Object.assign({}, record)
      if(that.dataForm.id){
        that.getGoodsMemberTypeList()
        that.getRenewal()
      }
    },
    getPaytypeList() {
      getAction('/pay/bisPayType/list', {
        pageNo: 1,
        pageSize: 9999,
        name: '6,7,10,11,12',
        state: 'Y',
        allowDeviceType: 'EF000000',
        column: 'sort',
        order: 'asc',
      }).then((res) => {
        if (res.success) {
          res.result.records.forEach((r) => {
            if (r.name_dictText.indexOf('payment') > -1) {
              r.name_dictText = r.name_dictText.split('payment')[0]
            } else {
              r.name_dictText = r.name_dictText.split('支付')[0]
            }
          })
          that.paytypeList = res.result.records
        } else {
          that.$message.error(res.message)
        }
      })
    },
    getRenewal() {
      getAction('/goods/bisGoodsRenewal/list', { goodsId: that.dataForm.id }).then((res) => {
        if (res.success) {
          if (res.result.total > 0) {
            that.renewalList = res.result.records
          } else {
            that.renewalList = [
              {
                type: '0',
                renewal: '',
              },
            ]
          }
        }
      })
    },
    getLevels() {
      that.levelList = []
      getAction('/member/bisMemberRule/list', { notNonmember: 1, manageState: 'Y', pageSize: 40 }).then((res) => {
        if (res.success) {
          that.levelList = res.result.records
          return
        }
      })
    },
    getGoodsMemberTypeList() {
      getAction('/goods/bisGoodsMemberType/list', { goodsId: that.dataForm.id }).then((res) => {
        if (res.success) {
          if (res.result.total > 0) {
            res.result.records.forEach((rs) => {
              rs.disable = true
            })
            that.elevation = res.result.records
          } else {
            that.elevation = [
              {
                memberType: undefined,
                memberTypeAfter: undefined,
                disable: false,
              },
            ]
          }
        }
      })
    },
    clickIsGift(record) {
      if (record.isGiftState == true) {
        that.$set(record, record.isGiftState, false)
      }
      if (record.isGiftState == false) {
        that.$set(record, record.isGiftState, true)
      }
    },
    filterTreeNode(inputValue, treeNode) {
      // 假设输入格式为 "级别:关键词" 如 "2:电器"
      const match = inputValue.match(/([123]):(.+)/)
      if (match) {
        const level = parseInt(match[1])
        const keyword = match[2]
        const nodeLevel = this.getNodeLevel(treeNode)
        
        if (nodeLevel !== level) return false
        return treeNode.data.props.title.includes(keyword)
      }
      
      // 默认搜索
      return treeNode.data.props.title.includes(inputValue)
    },
    getNodeLevel(node) {
      let level = 1
      let parent = node.parent
      while (parent) {
        level++
        parent = parent.parent
      }
      return level
    },
    select() {
      let param = {}
      param.pageNo = 1
      param.pageSize = 9999
      param.column = 'sort'
      param.order = 'asc'
      getAction('/goods/bisGoodsKind/rootList', param).then((res) => {
        if (res.success) {
          if (res.result.records.length > 0) {
            res.result.records.forEach((col) => {
              col.key = '' + col.id
              col.value = '' + col.id
              col.title = '' + col.name
              col.id = '' + col.id
              col.pid = '' + col.pid
              col.hasChild = '' + col.hasChild
              if (col.hasChild != '0') {
                that.getHasChild(col)
              }
            })
            that.treeData = that.getDataByResult(res.result.records)
          } else {
            that.treeData = []
          }
        } else {
          that.$alert(res.message, that.$t('提示'), {
            confirmButtonText: that.$t('确定'),
            callback: (action) => {},
          })
        }
      })
    },
    getHasChild(record) {
      let query = {}
      query.pageNo = 1
      query.pageSize = 9999
      query.pid = record.id
      getAction('/goods/bisGoodsKind/rootList', query).then((res) => {
        if (res.success) {
          if (res.result.records.length > 0) {
            res.result.records.forEach((col) => {
              col.key = '' + col.id
              col.value = '' + col.id
              col.title = '' + col.name
              col.pid = '' + col.pid
              col.id = '' + col.id
              col.hasChild = '' + col.hasChild
              if (col.hasChild != '0') {
                that.getHasChild(col)
              }
            })
            record.children = that.getDataByResult(res.result.records)
            that.treeData = [...that.treeData]
          }
        } else {
          that.$message.warning(res.message)
        }
      })
    },
    getDataByResult(result) {
      return result.map((item) => {
        return item
      })
    },
    handleGoodsSearch(value, record) {
      that.getGoodsListTwo(record.goodsForm, value)
    },
    deleteGoods(a, b) {
      that.setMealGoodsTable.dataSource.forEach((col) => {
        if (col.goodsId == b.goodsId) {
          let index = that.setMealGoodsTable.dataSource.indexOf(col)
          that.setMealGoodsTable.dataSource.splice(index, 1)
        }
      })
    },
    selectGoods(record) {
      that.getGoodsListTwo(record.goodsForm)
    },
    handleGoodsChange(event) {
      that.getGoodsListTwo(event)
    },
    getGoodsFormList() {
      that.goodsFormList = []
      initDictOptions('bis_goods_infor.form').then((res) => {
        if (res.success) {
          that.goodsFormList = res.result.filter(item=>{
            return item.value != '5' && item.value != '7' && item.value != '11' && item.value != '13'
              && item.value != '16'  && item.value != '17' && item.value <= 18
          })
        }
      })
    },
    getGoodsListTwo(form, value) {
      let querydata = {}
      querydata.pageIndex = 1
      querydata.pageSize = 10
      querydata.form = form
      querydata.goodsInfo = value
      let tId = Vue.ls.get(TENANT_ID)
      if(!tId){
        querydata.tenantId = 0
      }
      getAction('/goods/bisGoodsInfor/list', querydata).then((res) => {
        if (res.success) {
          that.addGoodsListTwo = res.result.records
        }
      })
    },
    changelimitCycleState(e) {
      if (e == '0') {
        that.limitCycledisable = true
      } else {
        that.limitCycledisable = false
      }
    },
    handleAllowWarns(e) {
      if (e) {
        that.allowWarnsdisable = true
      } else {
        that.allowWarnsdisable = false
      }
    },
    getTypeValue(e) {
      if (e.target.value == 'part') {
        that.memberShow = true
      } else {
        that.memberShow = false
      }
    },
    getDeviceTypeValue(e) {
      if (e.target.value == 'part') {
        that.deviceTypeShow = true
      } else {
        that.deviceTypeShow = false
      }
    },
    getDeviceValue(e) {
      if (e.target.value == 'part') {
        that.deviceShow = true
      } else {
        that.deviceShow = false
      }
    },
    getMemberList() {
      getAction('/member/bisMemberRule/list').then((res) => {
        if (res.success) {
          that.memberList = res.result.records
        }
      })
    },
    getDeviceTypeList() {
      getAction('/device/bisDeviceInfo/getTypeList', { kind: 0 }).then((res) => {
        if (res.success) {
          that.deviceTypeList = res.result.records
        }
      })
    },
    getDeviceList() {
      let kind = 0
      let type = ''
      if (that.allowDeviceType == 'part') {
        if (that.dataForm.allowDeviceTypes) {
          type = that.dataForm.allowDeviceTypes.join(',')
        }
      }
      getAction('/device/bisDeviceInfo/nameList', {
        pageSize: 999,
        type: type,
        kind: kind,
        column: 'type',
        order: 'ASC',
      }).then((res) => {
        if (res.success) {
          that.deviceList = res.result.records
        }
      })
    },
    close() {
      that.$emit('close')
      that.visible = false
    },
    handleOk() {
      let querydata = {}
      that.$refs.dataForm.validate((valid) => {
        if (valid) {
          if (that.chargeAfter) {
            that.dataForm.allowPromote = 1
            let arr = that.elevation.filter((el) => {
              return el.disable
            })
            if (arr.length == 0) {
              that.$message.warn(that.$t('至少设置一条晋级规则'))
              return
            }
          } else {
            that.dataForm.allowPromote = 0
          }
          if (that.renewalAfter) {
            that.dataForm.allowRenewal = 1
            let arr = that.renewalList.filter((el) => {
              return el.renewal === ''
            })
            if (arr.length > 0) {
              that.$message.warn(that.$t('请设置续期规则'))
              return
            }
            that.dataForm.renewalList = that.renewalList
          } else {
            that.dataForm.allowRenewal = 0
          }
          if (that.dataForm.allowMemberDiscounts == true) {
            that.dataForm.allowMemberDiscount = 'Y'
          } else {
            that.dataForm.allowMemberDiscount = 'N'
          }
          if (that.dataForm.allowOuts == true) {
            that.dataForm.allowOut = 'Y'
          } else {
            that.dataForm.allowOut = 'N'
          }
          if (that.dataForm.allowWarns == true) {
            that.dataForm.allowWarn = 'Y'
          } else {
            that.dataForm.allowWarn = 'N'
          }
          if (that.dataForm.allowLotterys == true) {
            that.dataForm.allowLottery = 'Y'
            if (that.dataForm.lottery == undefined || that.dataForm.lottery === '') {
              that.$message.warn(that.$t('彩票值不能为空'))
              return
            }
          } else {
            that.dataForm.allowLottery = 'N'
          }
          if (that.dataForm.allowCoins == true) {
            that.dataForm.allowCoin = 'Y'
            if (that.dataForm.coin == undefined || that.dataForm.coin === '') {
              that.$message.warn(that.$t('代币值不能为空'))
              return
            }
          } else {
            that.dataForm.allowCoin = 'N'
          }
          if (that.dataForm.allowPointss == true) {
            that.dataForm.allowPoints = 'Y'
            if (that.dataForm.points == undefined || that.dataForm.points === '') {
              that.$message.warn(that.$t('A币不能为空'))
              return
            }
          } else {
            that.dataForm.allowPoints = 'N'
          }
          if (that.dataForm.allowSales == true) {
            that.dataForm.allowSale = 'Y'
            if (that.dataForm.price == undefined || that.dataForm.price === '') {
              that.$message.warn(that.$t('售价不能为空'))
              return
            }
          } else {
            that.dataForm.allowSale = 'N'
          }
          if (that.dataForm.allowIntegrals == true) {
            that.dataForm.allowIntegral = 'Y'
            if (that.dataForm.integral == undefined || that.dataForm.integral === '') {
              that.$message.warn(that.$t('积分不能为空'))
              return
            }
          } else {
            that.dataForm.allowIntegral = 'N'
          }
          if (that.dataForm.allowAlotterys == true) {
            that.dataForm.allowAlottery = 'Y'
            if (that.dataForm.alottery == undefined || that.dataForm.alottery === '') {
              that.$message.warn(that.$t('A票值不能为空'))
              return
            }
          } else {
            that.dataForm.allowAlottery = 'N'
          }
          if (that.dataForm.authSales == true) {
            that.dataForm.authSale = 1
          } else {
            that.dataForm.authSale = 0
          }
          if (that.dataForm.limitCycle != '0') {
            if (that.dataForm.limitNum == undefined || that.dataForm.limitNum === '') {
              that.$message.warn(that.$t('限购数量不能为空'))
              return
            }
          }
          if (that.allowMemberType == 'part') {
            if (that.dataForm.allowMemberTypes == null || that.dataForm.allowMemberTypes == '') {
              that.$message.warn(that.$t('请选择会员类型'))
              return
            }
            that.dataForm.allowMemberType = that.dataForm.allowMemberTypes.join(',')
          } else {
            that.dataForm.allowMemberType = ''
          }

          if (that.allowDeviceType == 'part') {
            if (that.dataForm.allowDeviceTypes == null || that.dataForm.allowDeviceTypes == '') {
              that.$message.warn(that.$t('请选择适用渠道'))
              return
            }
            that.dataForm.allowDeviceType = that.dataForm.allowDeviceTypes.join(',')
          } else {
            that.dataForm.allowDeviceType = ''
          }

          if (that.allowDevice == 'part') {
            if (that.dataForm.allowDevices == null || that.dataForm.allowDevices == '') {
              that.$message.warn(that.$t('请选择适用终端'))
              return
            }
            that.dataForm.allowDevice = that.dataForm.allowDevices.join(',')
          } else {
            that.dataForm.allowDevice = ''
          }
          querydata = that.dataForm
          let arr = that.elevation.filter((el) => {
            return el.disable
          })
          querydata.bisGoodsMemberTypeList = arr
          querydata.bisGoodsPackageList = []
          that.setMealGoodsTable.dataSource.forEach((col) => {
            if (col.isGiftState) {
              col.isGift = 1
            } else {
              col.isGift = 0
            }
            if(col.goodsId!=''){
              querydata.bisGoodsPackageList.push(col)
            }
          })
          // 原材料
          querydata.bisGoodsMaterialList = []
          let x = that.recycleList.findIndex((rl) => {
            return rl.status == 'Y' && isEmpty(rl.recyclingType)
          })
          if (x > -1) {
            that.$message.warn(that.$t('请选择回收方式'))
            return
          }
          let y = that.recycleList.findIndex((rl) => {
            return rl.status == 'Y' && isEmpty(rl.recyclingValue, 1)
          })
          if (y > -1) {
            that.$message.warn(that.$t('请输入回收值'))
            return
          }
          let z = that.recycleList.findIndex((rl) => {
            return rl.status == 'Y'
          })
          if(z > -1 && querydata.bisGoodsPackageList.filter(g => {return g.goodsForm != '1'}).length > 0) {
            that.$message.warn(that.$t('仅支持回收实体形态的商品，请调整套餐子商品设置。'))
            return
          }
          let arr0 = []
          that.recycleList.forEach((l) => {
            arr0.push(l)
          })
          querydata.recyclingList = arr0
          let httpurl = ''
          let method = ''
          if (!that.dataForm.id) {
            httpurl += that.url.add
            method = 'post'
          } else {
            httpurl += that.url.edit
            method = 'put'
          }
          that.confirmLoading = true
          httpAction(httpurl, querydata, method)
            .then((res) => {
              if (res.success) {
                that.$message.success(res.message)
                that.$emit('ok')
                if (that.dataForm.id || !that.isContinue) {
                  that.close()
                } else {
                  that.initDataForm()
                }
              } else {
                that.$message.warning(res.message)
              }
            })
            .finally(() => {
              that.confirmLoading = false
            })
        }
      })
    },
    handleCancel() {
      that.close()
    },
    changeChargeStatue(e) {
      that.chargeAfter = e.target.checked
    },
    changeRenewalStatue(e) {
      that.renewalAfter = e.target.checked
    },
    addElevation() {
      that.elevation.push({
        memberType: undefined,
        memberTypeAfter: undefined,
        disable: false,
      })
    },
    deleteElevation(i) {
      that.elevation.splice(i, 1)
    },
    editElevation(i) {
      that.$set(that.elevation[i], 'disable', false)
    },
    saveElevation(item, i) {
      if (item.memberType && item.memberTypeAfter) {
        that.$set(that.elevation[i], 'disable', true)
      } else if (!item.memberType) {
        that.$message.warn(that.$t('请选择晋级前会员类型'))
      } else {
        that.$message.warn(that.$t('请选择晋级后会员类型'))
      }
    },
    changeAddState() {
      localStorage.setItem('goodsAddInfo', JSON.stringify({ state: that.isContinue }))
    },
    initDataForm() {
      that.dataForm = {
        code: '',
        name: '',
        allowOut: 'N',
        allowWarns: '',
        warnNum: 0,
        verifyType: '1',
        cost: '',
        allowMemberDiscount: 'N',
        allowCoins: '',
        allowLotterys: '',
        allowPointss: '',
        allowSale: 'N',
        allowIntegrals: '',
        allowAlotterys: '',
        authSale: '',
        authSales: false,
        state: 'Y',
        limitCycle: '0',
        allowMemberType: '',
        allowDevices: [],
        allowDevice: '',
        allowDeviceTypes: [],
        allowDeviceType: '',
        form: "5",
        species: '2',
        bisGoodsPackageList: [],
        recyclingList: [{ status: 'N' }],
      }
      that.chargeAfter = false
      that.elevation = [
        {
          memberType: undefined,
          memberTypeAfter: undefined,
          disable: false,
        },
      ]
      that.renewalAfter = false
      that.renewalList = [
        {
          type: '0',
          renewal: '',
        },
      ]
      that.allowWarnsdisable = true
      that.$refs.code.focus()
      that.edit(that.dataForm)
    },
    addNewGoods(record,index){
      let state=record.goodsForm
      nInd=index
      if (state == 9) {
        that.$refs.conponsForm.add(state,'meal')
        that.$refs.conponsForm.title = that.$t('新增优惠券')
        that.$refs.conponsForm.disableSubmit = false
      } else if (state == 14) {
        that.$refs.aCoInModalForm.add(state,'meal')
        that.$refs.aCoInModalForm.title = that.$t('新增')
        that.$refs.aCoInModalForm.disableSubmit = false
      } else if (state == 15) {
        that.$refs.timeLimitCoin.add(state,'meal')
        that.$refs.timeLimitCoin.title = that.$t('新增')
        that.$refs.timeLimitCoin.disableSubmit = false
      } else {
        that.$refs.modalForm.add(state,'meal')
        that.$refs.modalForm.title = that.$t('新增')
        that.$refs.modalForm.disableSubmit = false
      }
    },
    modalFormOk(obj){
      that.addGoodsListTwo.unshift(obj)
      that.$set(that.setMealGoodsTable.dataSource[nInd],'goodsId',obj.id)
    },
    changeSelectState(e){
      this.$set(this.dataForm, "allowTax", e.target.checked ? 1 : 0)
    }
  },
}
</script>
<style scoped>
.bold-font {
  font-weight: bold;
}
/deep/ .detail-upload .ant-upload-list-picture-card-container {
  width: 100%;
  height: 250px;
}
/deep/ .detail-upload .ant-upload-list-picture-card .ant-upload-list-item {
  width: 77% !important;
  height: 100% !important;
}
/deep/ .detail-upload .ant-upload .ant-upload-select .ant-upload-select-picture-card {
  width: 100%;
  height: 250px;
}
/deep/ .detail-upload .ant-upload {
  width: 77% !important;
  height: 100% !important;
}
</style>